package com.javaAPI.demo11;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {

    /**
     * 将date转换为字符串类型
     * 将字符串类型转换为date
     * 设计工具类
     * DateUtils 构造方法私有化
     */

    private static final String FORMAT_1  = "yyyy-MM-dd HH:mm:ss";

    private DateUtils() {
    }
    public static String getCuDateString(){
        return DateUtils.dateToString(new Date(),FORMAT_1);
    }

    public static String dateToString(Date date, String format) {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        return simpleDateFormat.format(date);
    }


    public static Date stringToDate(String strDate, String format) throws ParseException {

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        return simpleDateFormat.parse(strDate);
    }
}
